package com.yjck.fm.selfinfo.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.yjck.fm.selfinfo.service.SelfService;
import com.yjck.fm.util.MD5Utils;

@SuppressWarnings("serial")
public class SelfAction extends ActionSupport {
	private String passwd;
	private String newpass;
	private SelfService selfService;
	public void setSelfService(SelfService selfService) {
		this.selfService = selfService;
	}
	private InputStream inputStream;
	public String getNewpass() {
		return newpass;
	}
	public void setNewpass(String newpass) {
		this.newpass = newpass;
	}
	public InputStream getInputStream() {
		return inputStream;
	}
	
	public String getPasswd() {
		return passwd;
	}
	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}
	
	public String modify() throws Exception {
		String vemail = (String)ServletActionContext.getRequest().getSession().getAttribute("email");
		String password = MD5Utils.getMD5Str(passwd);
		if(selfService.checkPass(vemail, password)){
			if(selfService.modifyPass(vemail,MD5Utils.getMD5Str(newpass))){
				//修改密码
				inputStream = new ByteArrayInputStream("success".getBytes("UTF-8"));
			}else{
				//修改密码失败
				inputStream = new ByteArrayInputStream("fail".getBytes("UTF-8"));
			}
			
		}else{
			//密码不正确
			inputStream = new ByteArrayInputStream("passerror".getBytes("UTF-8"));
		}
		
		return "modify";
	}
}
